home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-29 | 4.3 KB | 141 lines | [TEXT/CWIE] |
- //================================================================================
- // Greg Anderson
- // db+
- //
- // Transaction object
- // 16, 17 May 1994
- //================================================================================
- #pragma once
-
- #ifndef __TRANSACTION__
- #define __TRANSACTION__
-
- #include "ReferenceTemplates.h"
-
- //
- // For REQUIREVALIDPOINTER
- //
- #include "Exceptions.h"
-
- //
- // For nil
- //
- #include <Types.h>
-
- class TTransactionAwareObject;
-
- //
- // Sticking with our technique of typesafe downcasting,
- // a transaction object must know about all of the
- // different object types and update pointer types that
- // it will ever need to deal with.
- //
- class TDBRecord;
- class TDBElement;
- class TDBProperty;
- class TDataRecord;
-
- //================================================================================
- // Class TUpdatePointerCollectionElement
- //
- // An update pointer collection element stores one item in a collection of
- // update pointers.
- //================================================================================
- class TUpdatePointerCollectionElement
- {
- private:
- TTransactionAwareObject* fUpdatePointer;
- TUpdatePointerCollectionElement* fNext;
-
- public:
- TUpdatePointerCollectionElement(TTransactionAwareObject* uptr, TUpdatePointerCollectionElement* chain) : fUpdatePointer(uptr), fNext(chain) { REQUIREVALIDPOINTER(uptr); }
- ~TUpdatePointerCollectionElement() { delete fNext; }
-
- TUpdatePointerCollectionElement* Next() { return fNext; }
- TTransactionAwareObject* UpdatePointer() { return fUpdatePointer; }
- };
-
- //================================================================================
- // Class TUpdatePointerCollection
- //
- // An update pointer collection keeps track of the update pointers that are
- // part of a given transaction.
- //================================================================================
- class TUpdatePointerCollection
- {
- private:
- TUpdatePointerCollectionElement* fFirst;
-
- public:
- TUpdatePointerCollection() : fFirst(nil) {}
-
- ~TUpdatePointerCollection()
- {
- this->ClearUpdatePointerCollection();
- }
-
- void ClearUpdatePointerCollection()
- {
- delete fFirst;
- fFirst = nil;
- }
-
- TUpdatePointerCollectionElement* First() { return fFirst; }
-
- void Add(TTransactionAwareObject* up)
- {
- //
- // We should throw if up is nil
- // (Actually, we should have already thrown before getting here)
- //
- if(up != nil)
- {
- TUpdatePointerCollectionElement* newUPCElement = new TUpdatePointerCollectionElement(up, fFirst);
- fFirst = newUPCElement;
- }
- }
- };
-
- //================================================================================
- // Class TUpdatePointerCollectinIterator
- //================================================================================
- class TUpdatePointerCollectionIterator
- {
- private:
- TUpdatePointerCollection* fUPCollection;
- TUpdatePointerCollectionElement* fCurrent;
-
- public:
- TUpdatePointerCollectionIterator(TUpdatePointerCollection* base) : fUPCollection(base), fCurrent(base->First()) { REQUIREVALIDPOINTER(base); }
-
- TUpdatePointerCollectionElement* Current() { REQUIREVALIDPOINTER(fCurrent); return fCurrent; }
- Boolean More() { return fCurrent != nil; }
- void Next() { if(fCurrent) fCurrent = fCurrent->Next(); }
- };
-
- //================================================================================
- // Class TTransaction
- //================================================================================
- class TTransaction : public TUpdatePointerCollection
- {
- public:
- ~TTransaction();
-
- TTransactionAwareObject* GetUpdatePointer(AConst<TTransactionAwareObject> object);
- AnUpdate<TDBRecord> GetDBRecordUpdatePointer(AConst<TTransactionAwareObject> cursor);
- AnUpdate<TDBElement> GetDBElementUpdatePointer(AConst<TTransactionAwareObject> cursor);
- AnUpdate<TDBProperty> GetDBPropertyUpdatePointer(AConst<TTransactionAwareObject> cursor);
- AnUpdate<TDataRecord> GetDataRecordUpdatePointer(AConst<TTransactionAwareObject> cursor);
-
-
- AnUpdate<TDBRecord> GetDBRecordUpdatePointer(AConst<TDBRecord> cursor);
- AnUpdate<TDBElement> GetDBElementUpdatePointer(AConst<TDBElement> cursor);
- AnUpdate<TDBProperty> GetDBPropertyUpdatePointer(AConst<TDBProperty> cursor);
- AnUpdate<TDataRecord> GetDataRecordUpdatePointer(AConst<TDataRecord> cursor);
-
- void CommitChanges();
- void DiscardChanges();
- };
-
- #endif
-